<template>
  <div class="goods-list">
    <router-link class="goods-item" v-for="item in goodslist" :key="item.id" :to="'/home/goodsInfo/' + item.id" tag="div">
      <img :src="item.img_url">
      <h1 class="title">{{item.title}}</h1>
      <div class="info">
        <p class="price">
          <span class="now">￥{{item.market_price}}</span>
          <span class="old">￥{{item.sell_price}}</span>
        </p>
        <p class="sell">
          <span>热卖中</span>
          <span>剩{{item.stock_quantity}}件</span>
        </p>
      </div>
    </router-link>
    <mt-button type="danger" size="large" @click="getMore">加载更多</mt-button>
  </div>
</template>

<script>
import {Toast} from 'mint-ui'
export default {
  data () {
    return {
      pageindex: 1,
      goodslist: []
    }
  },
  created () {
    this.getGoodsList()
  },
  methods: {
    getGoodsList () {
      this.$http.get('http://www.liulongbin.top:3005/api/getgoods?pageindex=' + this.pageindex).then(res => {
        if (res.body.status === 0) {
          console.log(res.body)
          this.goodslist = this.goodslist.concat(res.body.message)
        } else {
          Toast('加载详情失败...')
        }
      })
    },
    getMore () {
      this.pageindex++
      this.getGoodsList()
    }
  }
}
</script>

<style lang="scss" scoped>
.goods-list{
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  padding: 7px;
  background-color: #f9f9f9;
  .goods-item{
    background-color: #fff;
    width: 49%;
    margin-bottom: 7px;
    min-height: 230px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    img{
      width: 100%;
    }
    .title{
        font-size: 14px;
        padding: 0 8px;
        overflow: hidden;
        display: -webkit-box;
        -webkit-box-orient: vertical;
        -webkit-line-clamp: 2;
    }
    .info{
      padding: 0 8px;
      p{
        margin: 0;
      }
      .price{
        .now{
          color: red;
          font-size: 16px;
          font-weight: bold;
        }
        .old{
          text-decoration: line-through;
          font-size: 12px;
          margin-left: 6px;
        }
      }
      .sell{
        display: flex;
        justify-content: space-between;
        font-size: 13px;
      }
    }
  }
}
</style>
